Skip to content

fix: try fallback date patterns when mime4j rejects Date header#11224

Open
syyam wants to merge 1 commit into
thunderbird:mainfrom
syyam:fix/graceful-unparseable-dates
Open

fix: try fallback date patterns when mime4j rejects Date header#11224
syyam wants to merge 1 commit into
thunderbird:mainfrom
syyam:fix/graceful-unparseable-dates

Conversation

@syyam

@syyam syyam commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Closes #8714

When DefaultFieldParser (mime4j) fails to parse a Date: header, getSentDate() currently returns null with only a debug log. This leaves the message without a visible timestamp in the message list.

This change adds a tryFallbackDateParsing() helper that tries a list of common non-standard date formats found in real-world email headers — day-optional, 2-digit year, ISO-8601, and no-weekday variants. If a fallback matches, the parsed date is used. If all patterns fail, null is returned and a WARN-level log is written with the raw header value so it can be diagnosed and new patterns added.

Changes

  • MimeMessage.java: Added FALLBACK_DATE_PATTERNS list and tryFallbackDateParsing() helper; updated getSentDate() to invoke it on parse failure.

Test plan

  • Send/receive messages with non-standard dates (e.g. missing weekday, 2-digit year) and verify they display a timestamp instead of a blank
  • Messages with completely invalid date strings still show no timestamp (graceful null)
  • Existing messages with standard RFC 2822 dates are unaffected

When DefaultFieldParser fails to parse a Date header, the sent date
falls back to null, leaving the message without a timestamp in the list.
This adds a set of common non-standard date patterns (day-optional,
2-digit year, ISO-8601, no-weekday variants) tried in order before
giving up. Only legitimate parse failures are logged at WARN level.

Fixes thunderbird#8714
@github-actions

Copy link
Copy Markdown
Contributor

Missing report label. Set exactly one of: report: include, report: exclude OR report: highlight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unparseable dates should be handled more gracefully

2 participants